﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace PJOnimal
{
    class Button
    {
        Texture2D[] button; //2 trạng thái của nút
        int nButton = 0;
        public bool deChuotLen; //để chuột lên button
        public Vector2 toaDo;
        public Rectangle baoKhung;

        Texture2D[] text = new Texture2D[4];
        public bool[] showText;
        int nShowText = 0;

        Input input = new Input();

        Random random = new Random();

        public Button(Onimal game,string type)
        {
            switch (type)
            {
                case "menu":
                    nButton = 3;
                    nShowText = 4;
                    showText = new Boolean[nShowText];
                    button = new Texture2D[nButton];
                    button[0] = game.Content.Load<Texture2D>("UI/b1-" + random.Next(1, 5));
                    button[1] = game.Content.Load<Texture2D>("UI/b2-" + random.Next(1, 5));

                    for (int i = 0; i < nShowText; i++)
                        text[i] = game.Content.Load<Texture2D>("UI/text" + i);
                    break;
                case "select":
                    nButton = 5;
                    nShowText = 5;
                    showText = new Boolean[nShowText];
                    button = new Texture2D[nButton];
                    for (int i = 0; i < 5; i++)
                    {
                        button[i] = game.Content.Load<Texture2D>("Character/char" + (i+1) + "/00"); 
                    }
                    break;
            }
            
        }

        public void Update(GameTime gameTime)
        {
            baoKhung = new Rectangle((int)toaDo.X, (int)toaDo.Y, button[0].Width, button[0].Height);

            if (input.conChuot.Intersects(baoKhung))
                deChuotLen = true;
            else
                deChuotLen = false;

            input.Update(gameTime);
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw((deChuotLen) ? button[1] : button[0], toaDo, Color.White);

            for (int i = 0; i < nShowText; i++)
            {
                if (text[i] == null)
                    return;
                if (showText[i])
                    spriteBatch.Draw(text[i], new Vector2(toaDo.X + button[0].Width / 2, toaDo.Y + button[0].Height / 2), null, Color.White, 0f, new Vector2(text[i].Width / 2, text[i].Height / 2), 1f, SpriteEffects.None, 1f);
            }
        }
    }
}
